home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / oath.lha / oath / src / ensure.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-29  |  2.1 KB  |  56 lines

  1. //***************************************************************************
  2. //
  3. //  Copyright (C) 1990  Texas Instruments Incorporated
  4. //  Permission is granted to any individual or institution
  5. //  to use, copy, modify, and distribute this software,
  6. //  provided that this complete copyright and permission notice
  7. //  is maintained, intact, in all copies and supporting documentation.
  8. //
  9. //  Texas Instruments Incorporated provides this software "as is"
  10. //  without express or implied warranty.
  11. //
  12. //***************************************************************************
  13. //  ensure, assumed -- macros for verifying conditions at runtime
  14. //
  15. //  History:
  16. //    04/91  Brian M Kennedy  printAndAbort moved outline
  17. //    02/90  Brian M Kennedy  Original
  18. //
  19. //***************************************************************************
  20. //
  21. //  This file defines two macros used for catching errors.
  22. //
  23. //  ensure(C, S)
  24. //    This macro verifies that the condition C is true.  If not, it will
  25. //    print the string "Expected condition is false:" followed by the string S 
  26. //    and the filename and line number.  It then abort()'s, which should dump 
  27. //    core.
  28. //
  29. //  assumed(C, S)
  30. //    This macro is used to state a condition (C) that is assumed to be
  31. //    true by the programmer.  If NDEBUG is defined when this file is
  32. //    included, then assumed(C, S) will behave as ensure(C, S).  If it is 
  33. //    not defined when this file is included, then assumed(C, S) will do
  34. //    nothing at runtime.
  35. //
  36. //***************************************************************************
  37.  
  38. #include <oath/ensure.h>
  39.  
  40. #include <iostream.h>
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43.  
  44.     void
  45. printAndAbort (const char * S, const char * File, int Line)
  46.    {cerr << "Expected condition is false:" << endl;
  47.     if(*S != '\0')
  48.     cerr << "\t" << S << endl;
  49.     char Buffer[160];
  50.     sprintf(Buffer, "\tFile: \"%s\"\n\tLine: %d", File, Line);
  51.     cerr << Buffer << endl;
  52.     abort();  //exit and dump core
  53.    }
  54.  
  55. /***************************************************************************/
  56.